package com.dingreading.cloud.ssxcx.util;

import com.dingreading.cloud.common.util.KitUtil;
import com.dingreading.cloud.ssxcx.entity.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class XcxEntityUtils {

    public static XcxStudentLearningProgress newProgressBean(
            String agencyUid, String storeUid, String studentUid, String studentName, String telephone,
            String questionUid, String homeworkUid, String studentOptionUid, String subjectLessonUid, Integer materialStage,
            String projectUid, String stageUid, String versionUid
    ) {
        XcxStudentLearningProgress progress = new XcxStudentLearningProgress();
        progress.setUid(KitUtil.getUuid());
        progress.setAgencyUid(agencyUid);
        progress.setStoreUid(storeUid);
        progress.setStudentUid(studentUid);
        progress.setQuestionUid(questionUid);
        progress.setHomeworkUid(homeworkUid);
        progress.setSubjectLessonUid(subjectLessonUid);
        progress.setStudentOptionUid(studentOptionUid);
        progress.setMaterialStage(materialStage);
        progress.setEnabled(1);

        progress.setPhone(telephone);
        progress.setStudentName(studentName);
        progress.setProjectUid(projectUid);
        progress.setStageUid(stageUid);
        progress.setVersionUid(versionUid);

        progress.setAddStaffUid(studentUid);
        progress.setAddStaffName(studentName);
        progress.setLastStaffUid(studentUid);
        progress.setLastStaffName(studentName);
        return progress;
    }

    public static XcxStudentQuizAnswers newAnswersBean(
            XcxStudentQuizAnswers answer, String agencyUid, String storeUid, String subjectLessonUid,
            String studentUid, String studentName, String phone, String projectUid, String stageUid, String versionUid
    ) {
        answer.setUid(KitUtil.getUuid());
        answer.setAgencyUid(agencyUid);
        answer.setStoreUid(storeUid);
        answer.setSubjectLessonUid(subjectLessonUid);
        answer.setStudentUid(studentUid);
        answer.setEnabled(1);

        answer.setProjectUid(projectUid);
        answer.setStageUid(stageUid);
        answer.setStudentName(studentName);
        answer.setPhone(phone);
        answer.setVersionUid(versionUid);

        answer.setAddStaffUid(studentUid);
        answer.setAddStaffName(studentName);
        answer.setLastStaffUid(studentUid);
        answer.setLastStaffName(studentName);

        return answer;
    }

    public static XcxStudentHomework createNewHomework(
            String agencyUid, String storeUid, String studentUid, String studentName, String phone,
            String subjectLessonUid, String questionUid, Date nowDatetime, String projectUid, String stageUid, String versionUid
    ) {
        XcxStudentHomework newHomework = new XcxStudentHomework();
        newHomework.setUid(KitUtil.getUuid());
        newHomework.setAgencyUid(agencyUid);
        newHomework.setStoreUid(storeUid);
        newHomework.setStudentUid(studentUid);
        newHomework.setSubjectLessonUid(subjectLessonUid);
        newHomework.setQuestionUid(questionUid);
        newHomework.setStatus(1);
        newHomework.setSubmissionTime(nowDatetime);
        newHomework.setEnabled(1);

        newHomework.setStudentName(studentName);
        newHomework.setPhone(phone);
        newHomework.setProjectUid(projectUid);
        newHomework.setStageUid(stageUid);
        newHomework.setVersionUid(versionUid);

        newHomework.setAddStaffUid(studentUid);
        newHomework.setAddStaffName(studentName);
        newHomework.setLastStaffUid(studentUid);
        newHomework.setLastStaffName(studentName);
        return newHomework;
    }

    public static List<XcxHomeworkFiles> newHomeworkFiles(XcxStudentHomework existingHomework, List<String> imageUrls, String versionUid) {
        if (imageUrls == null || imageUrls.isEmpty()) {
            return null;
        }
        List<XcxHomeworkFiles> xcxHomeworkFiles = new ArrayList<>();
        for (String imageUrl : imageUrls) {
            XcxHomeworkFiles homeworkFiles = new XcxHomeworkFiles();
            homeworkFiles.setUid(KitUtil.getUuid());
            homeworkFiles.setHomeworkUid(existingHomework.getUid());
            homeworkFiles.setUrl(imageUrl);
            homeworkFiles.setEnabled(1);
            homeworkFiles.setVersionUid(versionUid);
            homeworkFiles.setAddStaffUid(existingHomework.getAddStaffUid());
            homeworkFiles.setAddStaffName(existingHomework.getAddStaffName());
            homeworkFiles.setLastStaffUid(existingHomework.getLastStaffUid());
            homeworkFiles.setLastStaffName(existingHomework.getLastStaffName());
            xcxHomeworkFiles.add(homeworkFiles);
        }
        return xcxHomeworkFiles;
    }

    public static XcxAnswersPandect newAnswersPandect(String studentUid, String studentName, String subjectLessonUid, String versionUid, boolean isAllCorrect) {
        XcxAnswersPandect xcxAnswersPandect = new XcxAnswersPandect();
        xcxAnswersPandect.setUid(KitUtil.getUuid());
        xcxAnswersPandect.setStudentUid(studentUid);
        xcxAnswersPandect.setSubjectLessonUid(subjectLessonUid);
        xcxAnswersPandect.setVersionUid(versionUid);
        xcxAnswersPandect.setIsAllCorrect(isAllCorrect ? 1 : 0);
        xcxAnswersPandect.setEnabled(1);

        xcxAnswersPandect.setAddStaffUid(studentUid);
        xcxAnswersPandect.setAddStaffName(studentName);
        xcxAnswersPandect.setLastStaffUid(studentUid);
        xcxAnswersPandect.setLastStaffName(studentName);
        return xcxAnswersPandect;
    }

    public static XcxHomeworkFilesTrack newFilesTrack(String finalName) {
        XcxHomeworkFilesTrack xcxHomeworkFilesTrack = new XcxHomeworkFilesTrack();
        xcxHomeworkFilesTrack.setUid(KitUtil.getUuid());
        xcxHomeworkFilesTrack.setUrl(finalName);
        xcxHomeworkFilesTrack.setStatus(1);
        return xcxHomeworkFilesTrack;
    }
}
